package com.iqik.base.alg;

import java.util.Arrays;

public class PrimeNumber {

    public static int countPrimes(int n) {
        int num = 0;
        boolean[] isPrim = new boolean[n];
        Arrays.fill(isPrim, true);
        for (int i = 2; i < n; i++) {
            // 如果当前是素数
            if (isPrim[i]) {
                num ++;
                for (int j = i * i; j < n; j+=i) {
                    isPrim[j] = false;
                }
            }
        }
        return num;
    }

    public static void main(String[] args) {
        int i = countPrimes(499979);
        System.out.println(i);
    }
}
